<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>1.localStorage的使用</title>
		<style>
			*{
				margin-bottom: 20px;
			}
		</style>
	</head>
	<body>
		<button onclick="save()">向localStorage中存入一个人</button>
		<button onclick="read()">从localStorage中根据key取出value</button>
		<button onclick="update()">更新localStorage中指定key所对应的value</button>
		<button onclick="shanchu()">删除localStorage中指定key的那条记录</button>
		<button onclick="qingkong()">清空localStorage</button>

		<script type="text/javascript" >
			let person = {
				name:'张三',
				age:18
			}
			let person2 = {
				name:'李四',
				age:19
			}

			//存数据，值得注意的是：如果存入的是非基本类型，那么就要JSON.stringify
			function save(){
				localStorage.setItem('ren',JSON.stringify(person))
			}

			//读数据
			function read(){
				let result = localStorage.getItem('qwe')
				console.log(result)
				console.log(JSON.parse(result))
			}

			//更新数据
			function update(){
				localStorage.setItem('ren',JSON.stringify(person2))
			}

			//删除指定数据
			function shanchu(){
				localStorage.removeItem('ren')
			}

			//清空
			function qingkong(){
				localStorage.clear()
			}

		</script>
	</body>
</html>